# @Time : 2020/7/28 17:41
# @Author : Fioman 
# @Phone : 13149920693
import cv2 as cv
import numpy as np

img = cv.imread("contours3.jpg")
cv.imshow("Original", img)

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
T, thresOtsu = cv.threshold(gray, 127, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
print(T,img.shape)
cv.imshow("ThresOtsu", thresOtsu)
image, contours, hierarchy = cv.findContours(thresOtsu, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)

mask = np.zeros(img.shape[:2], np.uint8) #
mask = cv.drawContours(mask, contours, -1, (255, 255, 255), -1)

cv.imshow("Mask", mask)
loc = cv.bitwise_and(img,img,mask=mask)
cv.imshow("location", loc)

cv.waitKey(0)
cv.destroyAllWindows()
